package com.ruiyangwang.ListenBook.servlet.album;

import com.ruiyangwang.ListenBook.util.DButil;
import com.ruiyangwang.ListenBook.util.Log;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * @author syzygy
 * @date 2022/07/21 17:53
 **/
@WebServlet("/studio/album/publish.do")
public class PublishDoServlet extends HttpServlet {
    @Override
    @SneakyThrows
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String aid = req.getParameter("aid");
        try(Connection c = DButil.connection()){
            String sql = "update albums set state = 2 where aid = ?";
            try(PreparedStatement ps = c.prepareStatement(sql)){
                ps.setString(1,aid);
                Log.println("执行sql" + ps);
                ps.executeUpdate();
            }
        }

        resp.sendRedirect("/studio/album/list.html");
    }
}